[Exchange-Online][EWS] - Getting unexpected "has invalid child element 'QueryString'" error.
Problem:

I'm trying to use EWS (not the Managed API) to send a FindItem query to Exchange Online. If I don't include a QueryString element, then I can retrieve all of the items in the designated folder, up to the MaxEntriesReturned attribute of the IndexedPageItemView element. 

The query I'm sending is:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope
 xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
 xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'
 xmlns:m='http://schemas.microsoft.com/exchange/services/2006/messages'
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
  <soap:Body>
    <m:FindItem Traversal='Shallow'>
      <m:ItemShape>
        <t:BaseShape>AllProperties</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI='item:Subject' />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned='1000' Offset='0' BasePoint='Beginning'/>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id='inbox'/>
      </m:ParentFolderIds>
      <m:QueryString>subject:Office</m:QueryString>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>
Based off of the example here: https://msdn.microsoft.com/EN-US/library/ee693615(v=exchg.150).aspx

When I POST this request to Exchange Online (https://outlook.office365.com/EWS/Exchange.asmx), I get the following response:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorSchemaValidation</faultcode>
      <faultstring xml:lang="en-US">The request failed schema validation: The element 'FindItem' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'QueryString' in namespace
 'http://schemas.microsoft.com/exchange/services/2006/messages'.</faultstring>
      <detail>
        <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorSchemaValidation</e:ResponseCode>
        <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request failed schema validation.</e:Message>
        <t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
          <t:LineNumber>1</t:LineNumber>
          <t:LinePosition>757</t:LinePosition>
          <t:Violation>The element 'FindItem' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'QueryString' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'.</t:Violation>
        </t:MessageXml>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>
As I said, if I remove the QueryString element from the request, everything works as expected. I tried changing the order of the elements in the request, but wherever I place the QueryString (other than last) I get a response indicating that the server is expecting a different element next.

The QueryString element clearly exists in the schema here: (you'll be asked to login using MS credentials if you aren't already logged in) https://outlook.office365.com/EWS/messages.xsd and the order of the elements matches the options here: https://msdn.microsoft.com/EN-US/library/aa566370(v=exchg.150).aspx

Is this a bug in the EWS API or can I do something differently in my request?
May 5th, 2015 8:44pm

Because AQS is a feature that was added in 2010 you need to version your request https://msdn.microsoft.com/en-us/library/office/dn741586(v=exchg.150).aspx else it will default to lowest schema 2007 where there was no QueryString. Eg to fix your query this should work fine

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2013_SP1" />
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal='Shallow'>
      <m:ItemShape>
        <t:BaseShape>AllProperties</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI='item:Subject' />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned='1000' Offset='0' BasePoint='Beginning'/>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id='inbox'/>
      </m:ParentFolderIds>
      <m:QueryString>subject:Office</m:QueryString>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>
Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
May 6th, 2015 4:04am

That's exactly what I was missing. Thanks!
May 6th, 2015 8:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics